//保存表格的实例对象
var sx = null;
//调用封装方法
getTable();

// ---------------------------------------------------
//方法区

//封装方法重载表格
function sxTable(){
    //通过表格id参数  重载刷新
    sx.reload()
}


//封装渲染表格
function getTable(){
    layui.use(['table','layer','jquery','form','laydate'],function() {
        //模板保存到变量上
        var laydate = layui.laydate;
        var table = layui.table;
        var layer = layui.layer;
        var form = layui.form;
        var $ = layui.$;

        //监听顶部搜索按钮
        form.on('submit(*)',function (d){
            console.log(d.field)
            var data = d.field;
            sx.reload({
                url:'/YltUser/AuditManage/getAuditListByLike',
                where:{
                    auditStats:data.auditStats,
                    userName:data.userName,
                    auditTime:data.auditTime
                }
            },true)
            return false
        })
        //监听顶部重置按钮
        form.on('submit(cz)',function (d){
            $("[name=auditStats]").val('')
            $("[name=userName]").val(undefined)
            $("[name=auditTime]").val(undefined)
            form.render()
            sx.reload({
                url:'/YltUser/AuditManage/getAuditList',
            },true)
            return false
        })

        // 渲染input日期
        laydate.render({
            elem:'#auditTime'
        })

        sx = table.render({
            elem:"#demo",
            url:"/YltUser/AuditManage/getAuditList",
            page:{
                layout:['count','prev','page','next','limit'],
                groups:5,
                limit:10,
                limits:[5,10,20]
            },
            cols:
                [[
                    // {field: 'auditId', title: '序号',width: 80,align: 'center'},
                    {field: 'userId', title: '用户编号',width: 100,align: 'center'},
                    {field: 'userAccount', title: '用户账号', width:150,align: 'center'},
                    {field: 'userName', title: '用户昵称',width: 150,align: 'center'},
                    {field: 'applyJob', title: '申请职位', width:120,align: 'center'},
                    {field: 'userPhone', title: '用户电话', width: 150, align: 'center'},
                    {field: 'auditTime', title: '申请时间', width: 200,align: 'center'},
                    {field: 'userEmail', title: '用户邮箱', width: 150,align: 'center'},
                    {field: 'auditStats', title: '申请状态', width: 150,align: 'center',templet:function (d){
                        if (d.auditStats == 0){
                            return '未审核';
                        }else if (d.auditStats == 1){
                            return '已通过';
                        }else {
                            return '已驳回';
                        }
                    }},

                ]],
            toolbar:'#toolbardemo',
            skin: 'line',
            parseData:function (res){
                return{
                    "code":res.code,
                    "msg":res.msg,
                    "count":res.count,
                    "data":res.data
                }
            }
        })
    })
}



